<template>
    <view class="content">
        <u-cell-group>
            <u-cell :value="item.deal_text" v-for="item in privatesealist" :key="item.id">
                <view slot="title" class="u-slot-title">
                    <view style="">
                        {{ item.nickname }}
                    </view>
                </view>
                <view slot="label" class="u-slot-label">
                    <view style="color:#909193">
                        客户来源：{{ item.source_text ? item.source_text : '未知' }}
                    </view>
                    <view class="btn">
                        <u-button type="primary" :customStyle="btnStyle" size="mini" text="详情"
                            @click="getToinfo(item.id)"></u-button>
                        <u-button type="success" :customStyle="btnStyle" size="mini" text="编辑"
                            @click="toEdit(item.id)"></u-button>
                        <u-button type="warning" :customStyle="btnStyle" size="mini" text="回收"
                            @click="getrecoverydata(item, 'warning')"></u-button>
                        <u-button type="error" :customStyle="btnStyle" size="mini" text="删除"
                            @click="getdeldata(item, 'error')">
                        </u-button>
                    </view>
                </view>
            </u-cell>
        </u-cell-group>
        <u-modal :show="show" :content='content' :showCancelButton="true" @confirm="confirm"
            @cancel="show = false"></u-modal>
		<u-button @click="toAdd" :customStyle="btnStyle1" color="#19BC9C" type="success">添加私海用户</u-button>
        <u-toast ref="uToast"></u-toast>
    </view>
</template>

<script>
export default {
    onLoad()
    {
        this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}

        this.$u.auth.check()

        this.getPrivateseaData()
    },
    data() {
        return {
			btnStyle1: {
			    width: '100%',
			    position: 'fixed',
			    bottom: '0px'
			},
            btnStyle: {
                width: '10%',
                display: "inline-block",
                marginRight: '5px',
                marginTop: '10px',
                lineHeight: '20px'
            },
            privatesealist: [],
            LoginUser: {},
            show: false,
            content: '确认是否删除当前用户?',
            // 客户id
            id: 0,
            // error: 表示是调用删除确认框， warning：表示是调用申请确认框
            status: 'error'
        }
    },
    methods: {
        async getPrivateseaData()
        {
			let data={
				id:this.LoginUser.id
			}
            let result = await this.$u.api.business.privateseaIndex(data)

            if(result.code === 1)
            {
                this.privatesealist = result.data
            }
        },
        getrecoverydata(value,status)
        {
            this.content = '确认是否回收' + value.nickname + '用户？'
            this.status = status

            this.show = true

            this.id = value.id
        },
        getdeldata(value,status)
        {
            this.content = '确认是否删除' + value.nickname + '用户？'

            this.status = status

            this.show = true

            this.id = value.id
        },
        async confirm()
        {
			let _this=this;
            this.show = false

            let result = {}

            if(this.status === 'error')
            {
                result = await this.$u.api.business.privateseaDel({busid:this.id,adminid:this.LoginUser.id})
            }else if(this.status === 'warning')
            {
                result = await this.$u.api.business.privateseaRecovery({busid:this.id,adminid:this.LoginUser.id})
            }

            if(result.code === 1)
            {
                this.$refs.uToast.show({
                    type:'success',
                    message:result.msg,
					complete(){
						_this.getPrivateseaData()
					}
                })

                return false
            }else{
                this.$refs.uToast.show({
                    type:'error',
                    message:result.msg
                })

                return false
            }
        },
        getToinfo(busid)
        {
            this.$u.route({
                url:'/packageB/privatesea/info',
                params:{
                    busid:busid
                }
            })
        },
		toEdit(busid) {
            this.$u.route({
                url:'/packageB/privatesea/edit',
                params:{
                    busid:busid
                }
            })
        },
		toAdd(){
			this.$u.route({
			    url:'/packageB/privatesea/add',
			})
		}
    },
}
</script>